
$(function() {
	$('#all').transfer({
		to: '#to',
		searchId: '#search',
		dblClick: true,
		searchText: '{count} options matching {keyword}',
		searchTextId: '#searchText',
		addId: '#addT',
		removeId: '#removeT', 
		addAllId: '#addAllT', 
		removeAllId: '#removeAllT',
		tClass: 'added'
	});
	
	$('#t1').datepicker(_date1_option);
	$('#t2').datepicker(_date1_option);
	$('#date').datepicker(_date1_option);
	
	new $.cleditor("content", {width:550, height:300});
    cleditor.focus();
     
    _send($('#send').val());
    $('#send').change(function() {
    	_send($(this).val());
	});
    
    $("#subject").attr("disabled", true);
    // $("#content").attr("disabled", true);
    
    $("#button_filter").click(function() {		
		var url = "customer.php?do=Email.ajax_enquiry";
		
		var form = $("#form_add")[0];
		
		var body = { };
		body.email_s = form.email.value;		
		body.t1_s = form.t1.value;
		body.t2_s = form.t2.value;
		
		body.num = form.num.value;
		body.day = form.day.value;
 		
 		$.getJSON(url, body, function(j) { 			
 			var options = [], i = 0, o = null;
             			
 			var target = $('#all');
 			target.empty();
 			
           for (i = 0; i < j.length; i++) {
        	   o = document.createElement("OPTION");
        	   o.value = typeof j[i] == 'object' ? j[i]['email'] : j[i];
        	   o.text = (i+1) + "/" + (typeof j[i] == 'object' ? j[i]['email'] : j[i]);
        	   target.get(0).options[i] = o;
            }
 		});
		
	});
});
